import React, { Component } from 'react';
import store from "../store"
import { withRouter } from "react-router-dom"
// export default Login;

function checkLogin(Com) {
    class LoginHoc extends Component {

        constructor(props) {
            super(props)

            console.log(props.location, 'location')

            if (!store.getState().user.token) {

                // 
                this.props.history.push({ pathname: '/login', state: { redirectTo: props.location.pathname } })
            }
        }
        render() {
            return (
                <>
                    <Com {...this.props} />
                </>
            );
        }
    }
    return withRouter(LoginHoc)
}

export default checkLogin